package com.odm.communitymanage.ui.notifications

import android.os.Bundle
import android.widget.TextView
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.ResourceUtils
import com.jeremyliao.liveeventbus.LiveEventBus
import com.odm.communitymanage.R
import com.odm.communitymanage.base.BaseFragment
import com.odm.communitymanage.core.Constants
import kotlinx.android.synthetic.main.fragment_notice_detail.*

/**
 * @description: 通知详情页面
 * @author: ODM
 * @date: 2020/4/15
 */
class NoticeDetailFragment : BaseFragment() {

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initLiveEvent()
    }

    override fun initViews() {

    }

    private fun initLiveEvent(){
        LiveEventBus.get(Constants.EVENT_NOTICE_DETAIL,NoticesFragment.NoticeData::class.java)
            .observeSticky(this ,
                Observer<NoticesFragment.NoticeData> {
                    tvContent_NoticeDetail?.text = it.content
                    tvTime_NoticeDetail?.text = it.start_time
                    tvTitle_NoticeDetail?.text = it.title
                    when(it.type){
                        0 -> {
                            tvType_NoticeDetail?.text = "通知"
                            tvType_NoticeDetail?.setTextColor(ColorUtils.string2Int("#FF8A8A"))
                            tvType_NoticeDetail?.background = ResourceUtils.getDrawable(R.drawable.shape_frame_red_no_radius)
                        }
                        1 -> {
                            tvType_NoticeDetail?.text = "调研"
                            tvType_NoticeDetail?.setTextColor(ColorUtils.string2Int("#61A4E4"))
                            tvType_NoticeDetail?.background = ResourceUtils.getDrawable(R.drawable.shape_frame_blue_no_radius)
                        }
                        2 -> {
                            tvType_NoticeDetail?.text = "公告"
                            tvType_NoticeDetail?.setTextColor(ColorUtils.string2Int("#FFA958"))
                            tvType_NoticeDetail?.background = ResourceUtils.getDrawable(R.drawable.shape_frame_orange_no_raidus)
                        }
                        3 -> {
                            tvType_NoticeDetail?.text = "投票"
                            tvType_NoticeDetail?.setTextColor(ColorUtils.string2Int("#64C8BC"))
                            tvType_NoticeDetail?.background = ResourceUtils.getDrawable(R.drawable.shape_frame_green_no_radius)

                        }
                    }
                })
    }


    override fun getLayoutId(): Int {
        return R.layout.fragment_notice_detail
    }
}